package com.sgxy.wmservice.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sgxy.commonutils.R;
import com.sgxy.wmservice.entity.WmGoods;
import com.sgxy.wmservice.entity.WmGoodsType;
import com.sgxy.wmservice.entity.vo.GoodsVo;
import com.sgxy.wmservice.entity.vo.StoreVo;
import com.sgxy.wmservice.service.WmGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author testjava
 * @since 2022-04-29
 */
@RestController
@RequestMapping("/wmservice/wmgoods")
public class WmGoodsController {

    @Autowired
    private WmGoodsService wmGoodsService;
    //获取分页列表
    @PostMapping("{page}/{limit}")
    public R index(@PathVariable Long page,
                   @PathVariable Long limit,
                   @RequestBody(required = false) WmGoods wmGoods){
        //System.out.println(1);
        Page<GoodsVo> goodsVoPage = new Page<>(page,limit);

        //QueryWrapper<WmGoods> wrapper = new QueryWrapper<>();
        //if(!StringUtils.isEmpty(wmGoods.getGoodsName())){
        //    wrapper.like("goods_name", wmGoods.getGoodsName());
        //}
        //wmGoodsService.page(rolePage,wrapper);
        wmGoodsService.selectPageVoList(goodsVoPage,wmGoods);
        return R.ok().data("items",goodsVoPage.getRecords()).data("total",goodsVoPage.getTotal());
    }

    //根据id获取
    @GetMapping("getGoodsType/{id}")
    public R getGoodsType(@PathVariable String id){
        GoodsVo goodsVo = wmGoodsService.selectOneById(id);
        return R.ok().data("goods", goodsVo);
    }
    @GetMapping("getGoodsAll")
    public R getRoleAll(){
        List<WmGoods> list = wmGoodsService.list(null);
        return R.ok().data("list",list);
    }
    @PostMapping("addGoods")
    public R addGoods(@RequestBody WmGoods wmGoods){
        wmGoodsService.save(wmGoods);
        return R.ok();
    }

    @PostMapping("updateGoods")
    public R updateGoods(@RequestBody WmGoods wmGoods){
        wmGoodsService.updateById(wmGoods);
        return R.ok();
    }
    @DeleteMapping("{id}")
    public R deleteGoodsById(@PathVariable String id){
        wmGoodsService.deleteGoodsById(id);
        return R.ok();
    }

}

